package ACM.zijie;

/**
 * @Author wwk
 * @DATE 2022/8/28 11:41
 */
import java.util.*;

public class third {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer>[] g = new ArrayList[n];

        for (int i = 0; i < g.length; i++) {
            g[i] = new ArrayList<>();
        }
        int[] inDegree = new int[10];
        ArrayList<Integer> needCompute = new ArrayList<>();
        scanner.nextLine();
        String[] tmp = scanner.nextLine().split(" ");
        for (String s : tmp) {
            needCompute.add(Integer.valueOf(s));
        }
        for (int i = 0; i < n - 1; i++) {
            tmp = scanner.nextLine().split(" ");
            if(tmp.length<=1){
                continue;
            }
            int from = Integer.parseInt(tmp[0]);
            for (int j = 0; j < tmp.length; j++) {
                int to = Integer.parseInt(tmp[j]);
                g[from].add(to);
                inDegree[to]++;
            }
        }
        Queue<Integer> fromQueue = new LinkedList<>();
        for (int i = 0; i < inDegree.length; i++) {
            if(inDegree[i]==0){
                fromQueue.offer(i);
            }
        }
        Map<Integer, Boolean> canCompute = new HashMap<>();
        while(!fromQueue.isEmpty()){
            int from = fromQueue.poll();
            canCompute.put(from, true);
            for(int to:g[from]){
                inDegree[to]--;
                if(inDegree[to]==0){
                    fromQueue.offer(to);
                }
            }
        }

        for (int i = 0; i < inDegree.length; i++) {
            if(inDegree[i]!=0){
                canCompute.put(i,reach(g,i,new boolean[inDegree.length]));
            }
        }
        List<String> ans = new ArrayList<>();
        for (Integer integer : needCompute) {
            Boolean orDefault = canCompute.getOrDefault(canCompute, false);
            if(orDefault){
                ans.add("1");
            }else{
                ans.add("0");
            }
        }
        System.out.println(String.join(" ",ans));

    }
    static  boolean reach(List<Integer>[] g, int from, boolean[] visited){
        if(visited[from]){
            return false;
        }
        if(g[from].size()==0){
            return true;
        }
        visited[from] = true;
        boolean result ;
        for(int to:g[from]){
            result = reach(g,to,visited);
            if(!result){
                return false;
            }
        }
        return true;
    }

}
